package com.thornbird.vehiclerecycling.model.record.property;

import com.thornbird.vehiclerecycling.util.JsonUtil;

import java.util.*;

public class RecordProperties {

    private List<String> ignoreProperties = new ArrayList<>();

    private Map<String, RecordProperties> entityProperties = new HashMap<>();

    public static RecordProperties of(String... properties) {
        RecordProperties recordProperties = new RecordProperties();
        recordProperties.addIgnoreProperties(properties);
        return recordProperties;
    }

    public List<String> getIgnoreProperties() {
        return ignoreProperties;
    }

    public Map<String, RecordProperties> getEntityProperties() {
        return entityProperties;
    }

    public void addIgnoreProperties(String... properties) {
        if (properties != null) {
            ignoreProperties.addAll(Arrays.asList(properties));
        }
    }

    private RecordProperties getChildIgnoreProperties(String... keys) {
        RecordProperties properties = this;
        for (String key : keys) {
            properties = properties.getEntityProperties().get(key);
        }
        return properties;
    }

    public RecordProperties clone() {
        return JsonUtil.parseObject(JsonUtil.toJsonString(this), RecordProperties.class);
    }

}
